package com.hry.store.service.impl;

import com.hry.store.dao.CategoryVoMapper;
import com.hry.store.service.CategoryVoService;
import com.hry.store.vo.CategoryVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Service
public class CategoryServiceImpl implements CategoryVoService {
    @Autowired
    private CategoryVoMapper categoryVoMapper;

    /**
     * 根据一级分类关联查询出二级分类
     *
     * @return
     */
    @Override
    public Map selectAllCategory() {
        List<CategoryVo> categoryVoList = categoryVoMapper.selectAllCategory();
        Map<Integer, List<CategoryVo>> listMap = categoryVoList.stream().collect(Collectors.groupingBy(CategoryVo::getTopCategoryId));

        System.out.println(listMap.get("topCategoryId"));

        return listMap;
    }
}
